package cn.itcast.controller;

import cn.itcast.entity.MessageConstant;
import cn.itcast.entity.Result;
import cn.itcast.pojo.Company;
import cn.itcast.service.CompanyService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("company")
public class CompanyController {

    @Reference
    private CompanyService companyService;

    //获取所有的公司地址集合
    @RequestMapping("/getAddress.do")
    public Result getAddress() {

        try {
            List<Company> list = companyService.findAll();
            ArrayList<Map> mapList = new ArrayList<>();
            for (Company company : list) {
                HashMap<String, String> map = new HashMap<String, String>();
                map.put("value",company.getAddress_name());
                mapList.add(map);
            }
            return new Result(true, MessageConstant.GET_COMPANY_ADDRESS_SUCCESS,mapList);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.GET_COMPANY_ADDRESS_FAIL);
        }
    }

}
